/***********************************************************
constants
***********************************************************/

// reference to the interface defined in nsIHelloWorld.idl
const nsIGridFTPClient = Components.interfaces.nsIGridFTPClient;

// reference to the required base interface that all components must support
const nsISupports = Components.interfaces.nsISupports;

// UUID uniquely identifying our component
// You can get from: http://kruithof.xs4all.nl/uuid/uuidgen here
const CLASS_ID = Components.ID("{0BE98302-64B0-11DD-AFC1-7DE255D89593}");

// description
const CLASS_NAME = "My GridFTPClient wrapper Javascript XPCOM Component";

// textual unique identifier
const CONTRACT_ID = "@pmcclory.gcl.udel.edu/gridftpclient;1";

/***********************************************************
class definition
***********************************************************/

//class constructor
function GridFTPClient() {
// If you only need to access your component from Javascript, uncomment the following line:
this.wrappedJSObject = this;
};

// class definition
GridFTPClient.prototype = {

  // define the function we want to expose in our interface
  /*
  hello: function() {
      return "Hello World!";
  },*/

  QueryInterface: function(aIID)
  {
    if (!aIID.equals(nsIGridFTPClient) &&    
        !aIID.equals(nsISupports))
      throw Components.results.NS_ERROR_NO_INTERFACE;
    return this;
  },
  
  
  _client : null,
  _host : null,
  _classLoader : null,
  _loaded : false,
  
  get client() { return this._client },
  set client(theClient) {return this._client=theClient },
  get loaded() { return this._loaded },
  set loaded(value) { return this._loaded=value },
  get classLoader() { return this._classLoader },
  set classLoader(loader) { return this.classLoader = loader}
};

/***********************************************************
class factory

This object is a member of the global-scope Components.classes.
It is keyed off of the contract ID. Eg:

myHelloWorld = Components.classes["@dietrich.ganx4.com/helloworld;1"].
                          createInstance(Components.interfaces.nsIHelloWorld);

***********************************************************/
var GridFTPClientFactory = {
  createInstance: function (aOuter, aIID)
  {
    if (aOuter != null)
      throw Components.results.NS_ERROR_NO_AGGREGATION;
    return (new GridFTPClient()).QueryInterface(aIID);
  }
};

/***********************************************************
module definition (xpcom registration)
***********************************************************/
var GridFTPClientModule = {
  registerSelf: function(aCompMgr, aFileSpec, aLocation, aType)
  {
    aCompMgr = aCompMgr.
        QueryInterface(Components.interfaces.nsIComponentRegistrar);
    aCompMgr.registerFactoryLocation(CLASS_ID, CLASS_NAME, 
        CONTRACT_ID, aFileSpec, aLocation, aType);
  },

  unregisterSelf: function(aCompMgr, aLocation, aType)
  {
    aCompMgr = aCompMgr.
        QueryInterface(Components.interfaces.nsIComponentRegistrar);
    aCompMgr.unregisterFactoryLocation(CLASS_ID, aLocation);        
  },
  
  getClassObject: function(aCompMgr, aCID, aIID)
  {
    if (!aIID.equals(Components.interfaces.nsIFactory))
      throw Components.results.NS_ERROR_NOT_IMPLEMENTED;

    if (aCID.equals(CLASS_ID))
      return GridFTPClientFactory;

    throw Components.results.NS_ERROR_NO_INTERFACE;
  },

  canUnload: function(aCompMgr) { return true; }
};

/***********************************************************
module initialization

When the application registers the component, this function
is called.
***********************************************************/
function NSGetModule(aCompMgr, aFileSpec) { return GridFTPClientModule; }